package com.xinzhi.log;

import com.xinzhi.mapper.LoginMapper;
import com.xinzhi.pojo.Useroperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Locale;
@Service
public class LoginLog{
    @Autowired
    private LoginMapper loginMapper;
    @Async("taskExecutor")
    public void insertLoginLog(Integer id, Integer status){
        Useroperation u = new Useroperation();
        u.setUserId(id);
        u.setUserstate(status);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH:mm:ss", Locale.CHINA);
        // 获取当前时间并格式化
        LocalDateTime now = LocalDateTime.now();
        u.setOperationtime(now.format(formatter));
        loginMapper.addLogin(u);
    }
}
